<template>
  <div>
      <el-form ref="form" :model="form" label-width="80px">
  <el-form-item label="用户名">
    <el-input v-model="form.username" :disabled="isupdate"></el-input>
  </el-form-item>
  <el-form-item label="密码">
    <el-input type="password" v-model="form.password" showpassword></el-input>
  </el-form-item>
  <el-form-item label="真实姓名">
    <el-input v-model="form.realname"></el-input>
  </el-form-item>
  <el-form-item label="电话号码">
    <el-input v-model="form.telephone"></el-input>
  </el-form-item>
  <el-form-item label="医生类型">
    <el-radio-group v-model="form.userType">
        <el-radio :label="1">门诊</el-radio>
        <el-radio :label="0">医技</el-radio>
      </el-radio-group>
  </el-form-item>
  <el-form-item label="医生级别">
     <el-select v-model="form.registLevel" placeholder="请选择">
          <el-option
            v-for="item in registerLevel"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
  </el-form-item>
  <el-form-item label="部门">
    <el-select v-model="form.deptId" placeholder="请选择">
          <el-option
            v-for="item in deptId"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="save()">保存数据</el-button>
  </el-form-item>
  
      </el-form>
  </div>
</template>

<script>
export default {
    name: 'Useredit',
    props:[
        'editid'
    ],
    data(){
        return {
            form: {
                id:this.editid,
                username:'',
                password:'',
                userType: 1,
                registLevelId: null,
                deptId: null
            },
            isupdate : false,
            url: '/ums-user/add',
            registerLevel: [],
            deptId: []
            
        }
    },
    methods: {
        save()
        {
            
            this.axios.post(this.url,response => {
                this.$emit('update:show',false)
                this.$emit('getdata')
            },
            this.form)
            
        },
        getData(){
            this.axios.get('/regist-level/list', response => {
                this.registerLevel = response.obj
            },{
                active: 1,
                withPage: 0
            })
            this.axios.get('/department/list', response => {
                this.deptId = response.obj
            },{
                active: 1,
                withPage: 0
            })
        }
    },
    created(){
        
        if(this.editid)
        {
            this.isupdate = true
            this.url = '/ums-user/update'
            this.axios.get('/ums-user/getById',response => {
                this.form = response.obj 
                this.form.password = ''
            },{id:this.editid})
        }
        this.getData()
    }
}
</script>

<style>

</style>